package com.tedu.webmagic.weather;

import com.tedu.webmagic.pojo.BaseDAO;
import us.codecraft.webmagic.ResultItems;
import us.codecraft.webmagic.Task;
import us.codecraft.webmagic.pipeline.Pipeline;

/**
 * 爬虫数据持久化
 */
public class PipelineImpl implements Pipeline {

    BaseDAO baseDAO = new BaseDAO();
    String sql = "INSERT INTO 'weather' ('tem','group','address')  VALUES(?,?,?)";
    /**
     * 得到public void process(Page page)  方法中发送的 数据，保存到数据库
     * @param resultItems
     * @param task
     */
    public void process(ResultItems resultItems, Task task) {

        Object name = resultItems.get("address");//地址
        Object group = resultItems.get("group");//最高温度
        Object tem1 = resultItems.get("tem1");//最低温度

        int update = baseDAO.update(sql, tem1, group, name);

        System.out.println("正在进行数据持久化："+update);

    }
}
